package com.gupaoedu.vip;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * <p>
 *
 * </p>
 *
 * @author Nicky
 * @since 2019-10-05
 */
public class RemotInvoktionHandler implements InvocationHandler {

  private String host;

  private int port;

  public RemotInvoktionHandler(String host, int port) {
    this.host = host;
    this.port = port;
  }

  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    System.out.println("come in");
    RpcRequest request = new RpcRequest();
    request.setClassName(method.getDeclaringClass().getName());
    request.setMethodName(method.getName());
    request.setParmters(args);

    RpcNetTransport rpcNetTransport = new RpcNetTransport(host,port);
    return rpcNetTransport.send(request);
  }
}
